﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace RushTracker.Web.HttpModules
{
    public class LanguageModule : IHttpModule
    {
        public void Dispose()
        {
            // nothing to see here, move along folks
        }

        public void Init(HttpApplication context)
        {
            context.BeginRequest += new EventHandler(context_BeginRequest);
        }

        private void context_BeginRequest(object sender, EventArgs e)
        {
            HttpApplication app = (HttpApplication)sender;

            string culture = "en-GB"; // read default language here

            if (app.Context.Request.Cookies["CultureInfo"] != null)
            {
                culture = app.Context.Request.Cookies["CultureInfo"].Value;
            }

            if (app.Context.User != null && app.Context.User.Identity.IsAuthenticated)
            {
                // set culture depending on language chosen by user
            }

            System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(culture);
        }
    }
}
